<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2017/11/6 14:35
 */

namespace App\Transformers\Api;

use App\Models\Patient;
use App\User;
use Illuminate\Support\Str;
use League\Fractal\TransformerAbstract;

class DoctorTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['records', 'physique'];

    public function transform(User $user)
    {
        //  病历信息
        $transform = [
            'id'              => $user->id,
            'name'            => $user->name,
            'sex'             => $user->sex,
            'phone'           => $user->phone,
            'hospital_id'     => $user->hospital_id,
            'birthday'        => $user->birthday,
            'medical_number'  => $user->medical_number,
            'diabetes_type'   => $user->diabetes_type,
            'special_illness' => $user->special_illness,
            'cardnumber'      => $user->CARDNUMBER,
            'nation'          => $user->nation,
            'province'        => $user->province,
            'city'            => $user->city,
            'county'          => $user->county,
            'invite_code'     => $user->INVITE_CODE,
        ];

        return $transform;
    }


    public function includePhysique(User $user)
    {
        return $this->item($user, function (User $user) {
            $data = (array)\DB::table('tn_doctor')->where('ACCOUNT', $user->account)->first();

//            if (!Str::startsWith($data['PIC'], 'http')) {
//                $data['PIC'] = 'http://www.365tang.cn/upload/face/' . $data['PIC'];
//            }

            return $data;
        });
    }


}